<template>
    <div
        class="dailyprepay-contnair"
        v-loading="isLoading"
        element-loading-background="rgba(250, 250, 250, 0.7)"
    >
        <!-- 按日贷款提前还款 -->
        <!-- <el-card
      shadow="never"
      v-loading="isLoading"
      element-loading-background="rgba(250, 250, 250, 0.7)"
    >
      <div slot="headerss" class="clearfix">
        <span>按日贷款提前还款</span>
        <el-button style="float: right; padding: 3px 20px;" type="text" @click="showTrial=false">关 闭</el-button>
        </div>-->
        <cardComponent pageTitle="按日贷">
            <template slot="cardBody">
                <el-form
                    ref="formRef"
                    :rules="Formrules"
                    :model="sizeForm"
                    label-width="95px"
                    size="small"
                >
                    <el-row>
                        <el-col :span="5">
                            <el-form-item label="账户类别 : ">
                                <el-input disabled v-model="sizeForm.CATEGORY" style="width: 100%;"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="主卡卡号 : ">
                                <el-input disabled v-model="sizeForm.CARDNBR" style="width: 100%;"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="起始日期 : " prop="BEGDAY">
                                <dataTime
                                    start
                                    @startT="startT"
                                    :endDates="sizeForm.ENDDAYA"
                                    :a="sizeForm.BEGDAY"
                                ></dataTime>
                                <!-- <el-input v-model="sizeForm.BEGDAY" style="width: 100%;" placeholder="格式:YYYMMDD"></el-input> -->
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="结束日期 : " prop="ENDDAYA">
                                <dataTime
                                    end
                                    @endT="endT"
                                    :startDates="sizeForm.BEGDAY"
                                    :b="sizeForm.ENDDAYA"
                                ></dataTime>
                                <!-- <el-input v-model="sizeForm.ENDDAYA" style="width: 100%;" placeholder="格式:YYYMMDD"></el-input> -->
                            </el-form-item>
                        </el-col>
                        <el-col :span="4" style="padding-left: 10px;">
                            <el-button type="primary" size="small" @click="onTrial('formRef')">查 询</el-button>
                            <el-button type="primary" size="small" @click="onReset">重 置</el-button>
                        </el-col>
                    </el-row>
                </el-form>
                <!-- </el-card> -->

                <!-- 按日贷款提前还款详情 -->
                <el-card style="width: 100%" shadow="never" v-if="showTrial">
                    <div slot="headerss" class="clearfix">
                        <span>按日贷款提前还款查询 (账户类别： {{sizeForm.CATEGORY}} )</span>
                        <el-button
                            style="float: right; padding: 3px 20px;"
                            type="text"
                            @click="showTrial=false"
                        >关 闭</el-button>
                    </div>
                    <div>
                        <el-table
                            :data="tableData"
                            border
                            stripe
                            style="width: 100%;"
                            highlight-current-row
                            @current-change="handleCurrentChange"
                            class="heard-bg business_table"
                        >
                            <el-table-column width="36">
                                <template slot-scope="scope">
                                    <el-radio v-model="id" :label="scope.row.APPREF">{{""}}</el-radio>
                                </template>
                            </el-table-column>
                            <el-table-column prop="APPREF" label="分期付款申请编号" min-width="135"></el-table-column>
                            <el-table-column prop="BEGYMDAY" label="分期付款交易日期" min-width="135"></el-table-column>
                            <el-table-column prop="PRODID" label="商品编号" min-width="100"></el-table-column>
                            <el-table-column prop="DESC1" label="商品名称" min-width="130"></el-table-column>
                            <el-table-column prop="MPAMT" label="贷款金额" min-width="100"></el-table-column>
                            <el-table-column prop="MPMTHS" label="贷款期数" min-width="77"></el-table-column>
                            <el-table-column prop="STATUS_1" label="状 态" min-width="110"></el-table-column>
                            <el-table-column prop="LOANDAY" label="贷款天数" min-width="100"></el-table-column>
                            <el-table-column prop="LOANDATE" label="贷款到期日" min-width="100"></el-table-column>
                        </el-table>
                        <div class="footer">
                            <el-button type="primary" size="small" @click="onCheXiao">提前还款查询</el-button>
                            <el-button type="primary" size="small" @click="onYanQi">按日贷延期</el-button>
                            <el-button
                                :disabled="currentPageIndex <= 0"
                                type="primary"
                                size="small"
                                @click="handleChangePage('pre')"
                            >上一页</el-button>
                            <el-button
                                :disabled="nextButtonFlag"
                                type="primary"
                                size="small"
                                @click="handleChangePage('next')"
                            >下一页</el-button>
                            <!-- <el-button size="small" @click="showTrial = false">关闭</el-button> -->
                        </div>
                    </div>
                </el-card>

                <!-- 提前还款查询窗口 -->
                <el-dialog
                    v-drag
                    class="dlog"
                    :title="elDialogTitel"
                    :visible="showchaxun"
                    append-to-body
                    @close="onReset1"
                    :show-close="false"
                    top="15vh"
                    center
                    width="1100px"
                    :close-on-click-modal="false"
                >
                    <el-form
                        ref="chaxunFormRef"
                        :rules="chaxunFormRules"
                        :model="chaxunDaily"
                        label-width="200px"
                        size="small "
                    >
                        <el-row>
                            <el-col :span="8">
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="卡号 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.CARDNBR"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="按日贷款申请编码 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.APPREF"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="所属贷款计划 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.CREDPID"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="按日贷款金额 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.MPAMT2"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="当前至贷款到期将产生息费 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.REMFEE2"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="贷款到期日 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.LOANDATE"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="未还账单金额与当期息费 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.PREPAYSTM"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="提前还款应还总额 : ">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.PREPAYAMT"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24" v-if="ifChaxun">
                                        <el-form-item label="还款类型 : " prop="OPERTP">
                                            <el-select
                                                :disabled="disableAll"
                                                @change="changeOPERTP"
                                                v-model="chaxunDaily.OPERTP"
                                                placeholder="请选择还款类型"
                                                style="width: 100%;"
                                            >
                                                <el-option label="全部还款" value="1"></el-option>
                                                <el-option label="部分还款" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-col>
                            <el-col :span="8">
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="证件号 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.CUSTID"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="贷款申请日期 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.INPDATE"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="商品编号 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.PRODID"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="贷款剩余本金 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.REMPPL"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="当前已产息费金额 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.REMFEE"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="贷款费率 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.LOANRATE"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="提前还款应还息费 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.PREPAYINF"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="提前还款应还本金 : " label-width="165px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.PREPAYPPL"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24" v-if="ifChaxun">
                                        <el-form-item
                                            label="免除手续费 : "
                                            label-width="165px"
                                            prop="CNLFEE"
                                        >
                                            <el-select
                                                :disabled="disableAll"
                                                v-model="chaxunDaily.CNLFEE"
                                                placeholder="请选择是否免除手续费"
                                                style="width: 100%;"
                                            >
                                                <el-option label="不免除" value="0"></el-option>
                                                <el-option label="免除" value="1"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-col>
                            <el-col :span="8">
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="按日贷款序号 : " label-width="150px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.MPNBR"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="状态 : " label-width="150px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.STATUS_1"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="币种 : " label-width="150px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.CURRNUM"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="贷款期数 : " label-width="150px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.MPMTHS2"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="贷款息费 : " label-width="150px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.FEEAMT"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="延期标识 : " label-width="150px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.DLYFLAG"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item label="延期天数 : " label-width="150px">
                                            <el-input
                                                disabled
                                                v-model="chaxunDaily.DLYDAYS"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24" v-if="ifChaxun">
                                        <el-form-item label>
                                            <el-input
                                                readonly
                                                class="b-0"
                                                value
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24" v-if="ifChaxun">
                                        <el-form-item
                                            label="还款金额 : "
                                            label-width="150px"
                                            prop="ACCEAMT"
                                        >
                                            <el-input
                                                :disabled="isDisables"
                                                v-model="chaxunDaily.ACCEAMT"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24" v-else>
                                        <el-form-item
                                            label="申请延期天数 : "
                                            label-width="150px"
                                            prop="DLYDAYS2"
                                        >
                                            <el-input
                                                :disabled="disableAll"
                                                v-model="chaxunDaily.DLYDAYS2"
                                                style="width: 100%;"
                                            ></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button
                            type="primary"
                            @click="onCheckDaily('chaxunFormRef')"
                            v-if="ifChaxun"
                        >提前还款</el-button>
                        <el-button
                            type="primary"
                            size="small"
                            @click="onYanQiDaily('chaxunFormRef')"
                            v-else
                        >延期还款</el-button>
                        <el-button type="primary" size="small" @click="onReset1">重 置</el-button>
                        <el-button @click="showchaxun = false">关 闭</el-button>
                    </div>
                </el-dialog>
            </template>
        </cardComponent>
    </div>
</template>

<script>
import { mapState } from 'vuex';
import moment from 'moment';
import cardComponent from '@/components/cardComponent/cardComponent.vue';
import dataTime from '@/components/datePocker/TimeStartToEnd.vue';
// import common from "../../../stores/common";
import { ChangePage, setNumber } from '@/utils/Object';
import { get_3xxx, get_4xxx } from '@/apis/getAPIClass';
import { getDictSelectList, getDictMappingValue } from '@/utils/Common';

export default {
    data() {
        return {
            sizeForm: {
                // 3052
                CATEGORY: '',
                CARDNBR: '',
                BEGDAY: '',
                ENDDAYA: '',
            },
            ifChaxun: true,
            chaxunDaily: {},
            tableData: [],
            STATUSList: [],
            Formrules: {
                BEGDAY: [
                    {
                        required: true,
                        message: '请输入开始时间',
                        trigger: ['change', 'blur'],
                    },
                ],
                ENDDAYA: [
                    {
                        required: true,
                        message: '请输入结束时间',
                        trigger: ['change', 'blur'],
                    },
                ],
            },
            chaxunFormRules: {
                OPERTP: [
                    {
                        required: true,
                        message: '请选择还款类型',
                        trigger: 'change',
                    },
                ],
                CNLFEE: [
                    {
                        required: true,
                        message: '请选择是否免除手续费',
                        trigger: 'change',
                    },
                ],
                DLYDAYS2: [
                    {
                        required: true,
                        message: '请输入申请延期天数',
                        trigger: 'blur',
                    },
                ],
                ACCEAMT: [
                    {
                        required: true,
                        message: '请输入提前还款金额！',
                        trigger: 'blur',
                    },
                    {
                        validator: (rule, value, callback) => {
                            if (value < 0.01) {
                                callback(new Error('输入金额不能小于0.01 ！'));
                            } else if (value > this.chaxunDaily.PREPAYPPL) {
                                callback(new Error('输入金额不能大于提前还款应还本金！'));
                            } else {
                                callback();
                            }
                        },
                        trigger: 'blur',
                    },
                ],
            },
            id: '',
            currentRow: null,
            pagingDataList: [], // 翻页上送字段列表
            currentPageIndex: 0, // 当前页,
            nextButtonFlag: true, // 下翻页按钮 显示控制阀
            showTrial: false,
            isLoading: false,
            showchaxun: false,
            MPNO: '0', // 翻页分期付款序号首次查询时送起始序号，默认为0 下翻页查询时上送上次查询结果的最后一条记录返回的交易序号
            RTNIND: '', // 首次查询上送空； 下翻页查询上送1；
            BEGYM: '00000000',
            isDisables: false,
            disableAll: false,
            _3121res: {},
            _3105res: {},
            _4095res: null,
            elDialogTitel: '',
        };
    },
    computed: {
        ...mapState({
            defaultParams: state => state.common.defaultParams, // 接口默认参数
            cardInfo_3004: state => state.common.cardInfo_3004,
            cardList_3601: state => state.common.cardList_3601,
            pinFlag: state => state.common.pinFlag, // 是否密码检查标志
        }),
    },
    name: 'dailyprepay',
    components: {
        cardComponent,
        dataTime,
    },
    async mounted() {
        // 获取账户类别
        const MY_CATEGORY = await getDictMappingValue('CATE', this.cardInfo_3004.CATEGORY, this) || this.cardInfo_3004.CATEGORY;
        this.sizeForm.CATEGORY = MY_CATEGORY;

        this.onLoadOBJ();
    },
    methods: {
        changeOPERTP(val) {
            if (val == '1') {
                this.chaxunDaily.ACCEAMT = this.chaxunDaily.PREPAYPPL;
                this.isDisables = true;
            } else {
                this.chaxunDaily.ACCEAMT = '';
                this.isDisables = false;
            }
            // this.chaxunDaily.ACCEAMT = 10
        },
        async onLoadOBJ() {
            this.sizeForm.CARDNBR = this.cardInfo_3004.CARDNO;
            this.STATUSList = await getDictSelectList('MPSTATUS', this);
            console.log(this.STATUSList);
            // this.sizeForm.CATEGORY = this.cardInfo_3004.CATEGORY;
        },
        handleCurrentChange(val) {
            this.currentRow = val;
            if (!val) return false;
            this.id = this.currentRow.APPREF;
        },
        // 查询请求 3121
        async onTrial(ref) {
            this.$refs[ref].validate((valid) => {
                if (!valid) return this.$message.error('验证错误，请核实填写数据！');
                // if (this.sizeForm.BEGDAY === "" || this.sizeForm.ENDDAY === "") {
                //   return this.$alert(`请输入查询的起始时间！`, "按日贷款提示！", {
                //     confirmButtonText: "确定",
                //     center: true,
                //     type: "warning ",
                //     showClose: false
                //   });
                // }
                let begdate = this.sizeForm.BEGDAY;
                begdate += '';
                begdate = begdate.trim();
                let enddate = this.sizeForm.ENDDAY;
                enddate += '';
                enddate = enddate.trim();
                const curDate = new Date();
                const cury = curDate.getFullYear();
                let curm = curDate.getMonth() + 1;
                let curd = curDate.getDate();
                if (curm < 10) curm = '0'.concat(curm);
                if (curd < 10) curd = '0'.concat(curd);
                const current = `${cury}${curm}${curd}`;

                // if (begdate > enddate) {
                //   return this.$alert(`开始时间不能大于结束时间`, "按日贷款提示！", {
                //     confirmButtonText: "确定",
                //     center: true,
                //     type: "warning ",
                //     showClose: false
                //   });
                // }
                // if (begdate > current) {
                //   return this.$alert(`开始时间不能大于当前日期`, "按日贷款提示！", {
                //     confirmButtonText: "确定",
                //     center: true,
                //     type: "warning ",
                //     showClose: false
                //   });
                // }
                this.id = '';
                this.pagingDataList = []; // 清空缓存 申请编号 -> 相当于首次查询
                this.MPNO = '0';
                this.RTNIND = '';
                this.BEGYM = '00000000';
                this.get_3121();
                // this.showTrial = true;
                this.isLoading = false;
            });
        },
        // 发送_3121请求
        async get_3121() {
            // 3121 配置请求头
            this.MPNO = setNumber(this.MPNO, 4, false);
            console.log(this.MPNO, this.BEGYM, 'appBody_3121');
            this.isLoading = true;
            const appBody_3121 = {
                CARDNBR: this.sizeForm.CARDNBR,
                OPERCODE: 0,
                PINFLAG: this.pinFlag,
                BEGDAY: this.sizeForm.BEGDAY,
                ENDDAY: this.sizeForm.ENDDAYA,
                RTNIND: this.pagingDataList.length === 0 ? '' : 1, // 翻页标志 首次传空， 翻页传1
                NEXTMPNO: this.MPNO,
                NEXTDAY: this.BEGYM,
            };

            let bool = false;
            if (this.pagingDataList.length == 0) bool = true;

            const result_3121 = await get_3xxx(
                '3121',
                '按日贷提前还款查询',
                appBody_3121,
                this,
                true,
                bool,
            );
            // if (!result_3121) return false;
            // 如果传过来的为空, 则无下翻页 ,将下翻按钮禁用
            if (!result_3121) {
                if (this.pagingDataList.length != 0) {
                    this.$message.warning('已经到最后一条数据');
                }
                this.nextButtonFlag = true;
                return false;
            }

            // this.showTrial = true;
            const res = result_3121.body.appBody.dataList;
            console.log(result_3121);
            res.forEach((item) => {
                item.MPAMT = item.MPAMT.toFixed(2);
                if ((`${item.BEGYM}`).trim()) item.BEGYMDAY = moment(`${item.BEGYM}`).format('YYYY-MM-DD');
                if ((`${item.LOANDATE}`).trim()) item.LOANDATE = moment(`${item.LOANDATE}`).format('YYYY-MM-DD');
                // 设置状态情况
                item.STATUS_1 = item.STATUS;
                this.STATUSList.forEach((i) => {
                    if ((`${item.STATUS}`).trim() == i.code) {
                        item.STATUS_1 = i.label;
                    }
                });
                // if ((item.STATUS + "").trim() == "C") item.STATUS = "完成";
                // if ((item.STATUS + "").trim() == "N") item.STATUS = "新增的";
                // if ((item.STATUS + "").trim() == "P") item.STATUS = "提前还款";
                // if ((item.STATUS + "").trim() == "A") item.STATUS = "正在分摊中";
            });
            this.tableData = [...res];
            this.showTrial = true;
            // 翻页设置
            ChangePage(this, ['BEGYM', 'MPNO'], 'tableData', 5);
        },
        // 提前还款查询 3105
        async onCheXiao() {
            if (this.currentRow === null) {
                return this.$alert('请选择一条记录列表！', '按日贷提前还款查询提示！', {
                    confirmButtonText: '确定',
                    center: true,
                    customClass: 'warning ',
                    showClose: false,
                });
            }
            this.ifChaxun = true;
            this.disableAll = false;
            // 请求 3105
            // this.showchaxun =true
            await this.get_3105();
            this.elDialogTitel = '提前还款申请';
            this.showchaxun = true;
        },
        // 提前还款操作
        async onCheckDaily(ref) {
            if (this.disableAll) return this.$message.warning('已操作,如需重新提交,请先重置!');
            this.$refs[ref].validate(async (valid) => {
                if (!valid) return this.$message.error('验证错误，请核实填写数据！');

                // 再次确定是否提前还款
                const confirmResult = await this.$confirm(
                    '此操作将提前还款申请, 是否继续?',
                    '按日贷提前还款提示',
                    {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        customClass: 'warning', type: 'warning',
                    },
                ).catch(err => err);
                if (confirmResult !== 'confirm') return this.$message.info('已取消按日贷提前还款');

                await this.get_4095(
                    this.chaxunDaily.OPERTP * 1,
                    this.chaxunDaily.ACCEAMT * 1,
                    '',
                    this.chaxunDaily.CNLFEE * 1,
                );

                await this.get_3105();


                this.disableAll = true;
                this.$refs.chaxunFormRef.resetFields();
                console.log(this._4095res);
                if (this._4095res) {
                    return this.$alert(
                        `当前提前还款 ${this._4095res.ACCEAMT} 元成功，请勿重复操作！`,
                        ' 提前还款操作成功！',
                        {
                            confirmButtonText: '确定',
                            center: true,
                            customClass: 'success', type: 'success',
                            showClose: false,
                        },
                    );
                }
            });
        },
        // 延期还款操作
        async onYanQiDaily(ref) {
            if (this.disableAll) return this.$message.warning('已操作,如需重新提交,请先重置!');
            this.$refs[ref].validate(async (valid) => {
                if (!valid) return this.$message.error('验证错误，请核实填写数据！');

                // 再次确定是否延期还款
                const confirmResult = await this.$confirm(
                    '此操作将延期还款申请, 是否继续?',
                    '按日贷延期还款提示',
                    {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        customClass: 'warning', type: 'warning',
                    },
                ).catch(err => err);
                if (confirmResult !== 'confirm') return this.$message.info('已取消按日贷延期还款');


                await this.get_4095(3, 0, this.chaxunDaily.DLYDAYS2, '');

                await this.get_3105();
                this.disableAll = true;
                this.$refs.chaxunFormRef.resetFields();
                console.log(this._4095res);
                if (this._4095res) {
                    return this.$alert(
                        `当前申请延期还款 ${this._4095res.DLYDAYS} 天成功，请勿重复操作！`,
                        ' 延期还款操作成功！',
                        {
                            confirmButtonText: '确定',
                            center: true,
                            customClass: 'success', type: 'success',
                            showClose: false,
                        },
                    );
                }
            });
        },
        // 发送_3105请求
        async get_3105() {
            // 3105 配置请求头
            const appBody_3105 = {
                CARDNBR: this.sizeForm.CARDNBR,
                APPREF: this.currentRow.APPREF,
                PINFLAG: this.pinFlag,
            };
            const result_3105 = await get_3xxx(
                '3105',
                '按日贷提前还款查询',
                appBody_3105,
                this,
            );
            if (!result_3105) return false;
            const res = result_3105.body.appBody;
            res.REMPPL = res.REMPPL.toFixed(1);
            res.REMFEE = res.REMFEE.toFixed(1);
            res.MPAMT2 = res.MPAMT2.toFixed(1);
            res.PREPAYAMT = res.PREPAYAMT.toFixed(1);
            res.PREPAYPPL = res.PREPAYPPL.toFixed(1);
            if ((`${res.INPDATE}`).trim()) res.INPDATE = moment(`${res.INPDATE}`).format('YYYY-MM-DD');
            if ((`${res.LOANDATE}`).trim()) res.LOANDATE = moment(`${res.LOANDATE}`).format('YYYY-MM-DD');
            if ((`${res.CURRNUM}`).trim() == 156) res.CURRNUM = '人民币';
            if ((`${res.STATUS}`).trim() == 30) res.STATUS_1 = '待请款';
            if ((`${res.STATUS}`).trim() == 90) res.STATUS_1 = '已撤销';

            // 设置状态情况
            res.STATUS_1 = res.STATUS;
            this.STATUSList.forEach((i) => {
                if ((`${res.STATUS}`).trim() == i.code) {
                    res.STATUS_1 = i.label;
                }
            });

            // if ((res.STATUS + "").trim() == "N") res.STATUS = "已请款待摊销";
            // if ((res.STATUS + "").trim() == "A") res.STATUS = "正常摊销";
            // if ((res.STATUS + "").trim() == "C") res.STATUS = "正常结束";
            // if ((res.STATUS + "").trim() == "P") res.STATUS = "提前还款";


            if ((`${res.DLYFLAG}`).trim() == '0') res.DLYFLAG = '未延期';
            if ((`${res.DLYFLAG}`).trim() == '1') res.DLYFLAG = '延期中';

            this.chaxunDaily = {
                OPERTP: '', CNLFEE: '', ACCEAMT: '', DLYDAYS2: '', ...res,
            };
            // this.chaxunDaily = { ...this.chaxunDaily , ...res };
            this._3105res = result_3105.body.appBody;
        },
        // 按日贷延期 3105
        async onYanQi() {
            if (this.currentRow === null) {
                return this.$alert('请选择一条记录列表！', '按日贷撤销延期查询提示！', {
                    confirmButtonText: '确定',
                    center: true,
                    customClass: 'warning ',
                    showClose: false,
                });
            }

            this.disableAll = false;
            this.ifChaxun = false;
            // 请求 3105
            // this.showchaxun =true
            await this.get_3105();
            this.elDialogTitel = '按日贷延期还款申请';
            this.showchaxun = true;
            // 判断当前选择条的状态,再确定是否执行下一步 //延期标识0-未延期  1-延期中
            // if(this._3105res.DLYFLAG.trim() == "0")
            // if(this._3105res.DLYFLAG.trim() == "1")
            // 状态 N-已请款待摊销 A-正常摊销 C-正常结束P-提前还款30-待请款90-已撤销
            // if(this._3105res.STATUS.trim() != "30")
            // return this.$alert(
            //         `状态不是待请款，不能取消！`,
            //         "按日贷款撤销！",
            //         {
            //           confirmButtonText: "确定",
            //           center: true,
            //           type: "warning ",
            //           showClose: false
            //         }
            //       );
        },

        // 请求 4095接口
        async get_4095(OPERTP, ACCEAMT = 0, DLYDAYS = '', CNLFEEYN = 0) {
            this._4095res = null;
            // 4095 配置请求头
            const appBody_4095 = {
                CARDNBR: this.sizeForm.CARDNBR,
                APPREF: this.currentRow.APPREF,
                OPERTP, // 0:撤销1:全额提前还款2:部分提前款款3:延期4:提前还款试算5：延期撤销
                MPNBR: this._3105res.MPNBR,
                CNLFEE: CNLFEEYN || '', // 免除手续费
                PINFLAG: this.pinFlag,
                // CNLFEEYN:CNLFEEYN,
                ACCEAMT: setNumber(ACCEAMT, 11), // 提前还款金额
                DLYDAYS, // 延期天数
            };
            console.log(appBody_4095);

            const result_4095 = await get_4xxx(
                '4095',
                '按日贷提前还款',
                appBody_4095,
                this,
            );
            if (!result_4095) return false;
            this._4095res = result_4095.body.appBody;
            console.log(this._4095res);
            // this.$alert(`按日贷款操作成功！!"}`, "按日贷款撤销", {
            //   confirmButtonText: "确定",
            //   center: true,
            //   type: "success",
            //   showClose: false
            // });
            // 重新查询刷新页面
            // this.onQuery();
            // }
        },
        // 上下页切换
        handleChangePage(type) {
            this.currentRow = null;
            this.id = '';
            if (type === 'pre') {
                // 切换到上一页
                if (this.currentPageIndex - 2 < 0) {
                    this.pagingDataList = []; // 清空缓存 申请编号 -> 相当于首次查询
                    this.MPNO = '0';
                    this.RTNIND = '';
                    this.BEGYM = '00000000';
                } else {
                    this.currentPageIndex = this.currentPageIndex - 2;
                    this.MPNO = this.pagingDataList[this.currentPageIndex].MPNO;
                    this.BEGYM = this.pagingDataList[this.currentPageIndex].BEGYM;
                }
                this.get_3121();
            } else {
                // 切换到下一页
                this.get_3121();
            }
        },
        onReset() {
            this.sizeForm.BEGDAY = '';
            this.sizeForm.ENDDAY = '';
            this.tableData = [];
            this.$refs.formRef.resetFields();
        },
        // 重置提前还款
        onReset1() {
            this.disableAll = false;
            this.$refs.chaxunFormRef.resetFields();
        },
        startT(data) {
            this.sizeForm.BEGDAY = data;
        },
        endT(data) {
            this.sizeForm.ENDDAYA = data;
        },
    },
};
</script>

<style  scoped lang="scss">
.dailyprepay-contnair {
    /deep/.el-card__header {
        padding: 20px !important;
    }
    /deep/.form-row {
        width: 100%;
        margin: 0 auto;
        .el-form {
            //   text-align: left;
            margin: 0 auto;
            //   width: 500px;
            .el-form-item {
                text-align: left;
            }
        }
        .el-select {
            width: 100%;
            margin-bottom: 15px;
        }
    }
    .el-row {
        height: 35px;
    }
    .el-form-item {
        text-align: left;
    }
    /deep/.el-dialog__header {
        border-bottom: 1px solid #dcdfe6 !important;
    }
    .footer {
        text-align: center;
        margin-top: 10px;
    }
}
</style>
